<?php
/**
 * 同步时根据disqus那边返回的url取文章ID错误修正方法
 * */

ini_set('display_errors','on');
error_reporting( E_ALL );

//表前缀
define('DB_DEBUG',true);

require_once 'config.php';
require_once '../conf/conf.php';
require_once 'class/Mysql.class.php';

$db = new Mysql();

$data = $db->getAll('comment', 'article_id = 0', 'cid, site, url');

foreach( $data as $k => $v ){
	$table = $site_config[$v['site']]['table'];
	$field = $site_config[$v['site']]['field_id'];
	
	$u = explode('/', $v['url']);
	$n = end( $u );
	
	$sql = "SELECT D_ID, Field_{$field} AS aid FROM Table_{$table} WHERE url LIKE '%/{$n}'";
	$d = $db->getOne( $sql );
	
	if( empty( $d ) ){
		echo '更新失败了  cid => ' .$v['cid']. ', 文章URL => '.$v['url'] . '<br />';
		continue;
	}
	
	$did = $d['D_ID'];
	$article_id = $d['aid'];
	
	$r = $db->update('comment', array('d_id'=>$did, 'article_id'=>$article_id,'is_c'=>1), 'cid = ' .$v['cid']);
	
	if( $r ) echo '更新成功了 cid => ' .$v['cid']. ', 文章ID => '.$article_id . ', 文章URL => '.$v['url'] .'<br />';
}


